package com.cmj.dao;

import com.cmj.domain.entity.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 评论表(Comment)表数据库访问层
 *
 * @author makejava
 * @since 2022-03-14 16:56:26
 */
 @Mapper
public interface CommentMapper {
    /***
     * 根据文章id查询所有根（父）评论
     *
     * @param commentType
     * @param articleId 文章id
     * @return 所有根（父）评论
     */
    List<Comment> commentList(@Param("commentType") int commentType, @Param("articleId") Long articleId);

    /***
     * 查询所有子评论
     * @param commentId 评论id
     * @return 子评论
     */
    @Select("select * from cmj_comment where root_id = #{commentId} order by create_time ASC")
    List<Comment> commentListChildren(Long commentId);

    /***
     * 添加评论
     * @param comment 评论信息
     */
    @Insert("insert into cmj_comment(type,article_id,root_id,content,to_comment_user_id,to_comment_id,create_by,create_time,update_by,update_time) " +
            "values(#{type},#{articleId},#{rootId},#{content},#{toCommentUserId},#{toCommentId},#{createBy},#{createTime},#{updateBy},#{updateTime})")
    void addComment(Comment comment);
}

